package com.ganbo.ms.java8.stream;

import com.ganbo.ms.java8.sort.Person;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author ganbo
 * @date 2022/12/18 9:42
 */
public class Demo2 {


    public static void main(String[] args) {
        List<String> one = Arrays.asList("迪丽热巴", "宋远桥", "苏星河", "老子", "庄子", "孙子", "洪七公", "逍遥子");
        List<String> two = Arrays.asList("古力娜扎", "张无忌", "张三丰", "赵丽颖", "张二狗", "张天爱", "张三");

        //1.第一个队伍只要名字为3各自的成员姓名
        one = one.stream().filter(o -> o.length() == 3).limit(3).collect(Collectors.toList());

        //3.第二队伍只要姓张的成员姓名
        two = two.stream().filter(o -> o.startsWith("张")).skip(2).collect(Collectors.toList());

        //5.将两个队伍合并为一个队伍
        List<String> three = Stream.concat(one.stream(), two.stream()).collect(Collectors.toList());
        System.out.println(three);

        three.stream().map(Person2::new).forEach(System.out::println);

        final ArrayList<String> collect = Stream.concat(one.stream(), two.stream()).collect(Collectors.toCollection(ArrayList::new)); //指定用ArrayList收集

        final Object[] objects = Stream.concat(one.stream(), two.stream()).toArray();   //收集到Object[]中

        final String[] strings = Stream.concat(one.stream(), two.stream()).toArray(String[]::new); //收集到String[]中


    }
}

@AllArgsConstructor
@NoArgsConstructor
@Data
class Person2 {
    private String name;
}

